package com.ydm.fire_fighting_web.util;

import io.lettuce.core.ScriptOutputType;

import java.text.SimpleDateFormat;
import java.util.Date;

public final class TimeUil {
    public static  String ComputationTime(String lastTime){
        char[] chars = lastTime.toCharArray();
        StringBuffer number  =  new StringBuffer();
        StringBuffer text  =  new StringBuffer();
        for (char aChar : chars) {
            if (Character.isDigit(aChar)){
                number.append(aChar);
            }else{
                text.append(aChar);
            }
        }
        long time = Integer.parseInt(number.toString());
        String substring = text.toString();
        long NextTime = 0;
        if(substring.equalsIgnoreCase("天")){
            NextTime = time * 86400000;
        }if(substring.equalsIgnoreCase("小时")){
            NextTime = time * 3600000;
        }if(substring.equalsIgnoreCase("分钟")){
            NextTime = time * 60000;
        }
        Date date = new Date();
        long time1 = date.getTime();
        long Lastime = time1-NextTime;
        date.setTime(Lastime);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        return format;
    }
}
